import pandas as pd
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.dates import DateFormatter
from pylab import mpl
# 读取日志文件
# 并将每一行分割为时间和占用百分比
# 设置中文显示字体
mpl.rcParams["font.sans-serif"] = ["SimHei"]

data = []
with open(r'C:\Users\11913\PycharmProjects\pythonProject1\pose_graph_mem.log', 'r') as f:
    for line in f:
        time_percentage = line.strip().split(',')
        if len(time_percentage) == 2:  # 确保每行数据包含两个值
            time_str, percentage = time_percentage
            data.append((pd.Timestamp(time_str), float(percentage)))

# 设置时间列为索引
df = pd.DataFrame(data, columns=['Time', 'Percentage'])
df.set_index('Time', inplace=True)

# 时间排序
df.sort_index(inplace=True)


plt.figure(figsize=(10, 6))
plt.plot(df['Percentage'], marker='o')

plt.title('占用百分比随时间变化')
plt.xlabel('时间')
plt.ylabel('占用百分比 (%)')
plt.grid(True)


ax = plt.gca()
ax.xaxis.set_major_formatter(DateFormatter('%H:%M:%S'))

plt.savefig("pose_graph_mem")


# 显示图形
plt.show()